<?php
defined('IN_ZEEGING') or die('Access Denied');
class Model extends Base{
	protected $dbLink=NULL;
	protected $dbConfigs=array();
	public function __construct(){
		$this->dbConfigs=$this->loadConfigs('database');
		$this->init();
	}
	protected function init(){
		$this->dbLink=mysqli_connect($this->dbConfigs['hostname'],$this->dbConfigs['username'],$this->dbConfigs['password']);
		if (!$this->dbLink) {
		    echo "Error: Unable to connect to MySQL." . PHP_EOL;
		    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
		    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
		    exit;
		}
		mysqli_select_db($this->dbLink,$this->dbConfigs['database']) or die(mysqli_error($this->dbLink));
		mysqli_query($this->dbLink,'set names '.$this->dbConfigs['charset']);
	}
	public function query($sql){
		$res=mysqli_query($this->dbLink,$sql) or exit(mysqli_error($this->dbLink));
		return $res;
	}
	public function queryIgnoreError($sql){
		$res=mysqli_query($this->dbLink,$sql);
		return $res;
	}
	public function execute($sql){
		return mysqli_query($this->dbLink,$sql) ? true : false ;
	}
	public function fetch($res,$type='array'){
		$func=($type=='object') ? 'mysqli_fetch_object' : (($type=='assoc') ? 'mysqli_fetch_assoc' : 'mysqli_fetch_array') ;
		return $func($res);
	}
	
	public function checkInt($number){
		return intval($number);
	}
	public function checkStr($string){
		if (!get_magic_quotes_gpc()) {      
			return addslashes($string);      
		}      
		return $string;      
	}
	public function begin(){
		mysqli_query($this->dbLink,'BEGIN');
	}
	public function commit(){
		mysqli_query($this->dbLink,'COMMIT');
	}
	public function rollback(){
		mysqli_query($this->dbLink,'ROLLBACK');
	}
}
//------------------------------------------------
//End of File : /Core/Model.class.php
//------------------------------------------------